//
//  SearchMsg.m
//
//  Created by 啊  on 16/4/26
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "SearchMsg.h"


NSString *const kSearchMsgHtId = @"htId";
NSString *const kSearchMsgCreateTime = @"createTime";
NSString *const kSearchMsgHtTop = @"htTop";
NSString *const kSearchMsgHtSource = @"htSource";
NSString *const kSearchMsgCreateUser = @"createUser";
NSString *const kSearchMsgHtName = @"htName";


@interface SearchMsg ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation SearchMsg

@synthesize htId = _htId;
@synthesize createTime = _createTime;
@synthesize htTop = _htTop;
@synthesize htSource = _htSource;
@synthesize createUser = _createUser;
@synthesize htName = _htName;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.htId = [[self objectOrNilForKey:kSearchMsgHtId fromDictionary:dict] doubleValue];
            self.createTime = [self objectOrNilForKey:kSearchMsgCreateTime fromDictionary:dict];
            self.htTop = [[self objectOrNilForKey:kSearchMsgHtTop fromDictionary:dict] doubleValue];
            self.htSource = [self objectOrNilForKey:kSearchMsgHtSource fromDictionary:dict];
            self.createUser = [self objectOrNilForKey:kSearchMsgCreateUser fromDictionary:dict];
            self.htName = [self objectOrNilForKey:kSearchMsgHtName fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.htId] forKey:kSearchMsgHtId];
    [mutableDict setValue:self.createTime forKey:kSearchMsgCreateTime];
    [mutableDict setValue:[NSNumber numberWithDouble:self.htTop] forKey:kSearchMsgHtTop];
    [mutableDict setValue:self.htSource forKey:kSearchMsgHtSource];
    [mutableDict setValue:self.createUser forKey:kSearchMsgCreateUser];
    [mutableDict setValue:self.htName forKey:kSearchMsgHtName];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.htId = [aDecoder decodeDoubleForKey:kSearchMsgHtId];
    self.createTime = [aDecoder decodeObjectForKey:kSearchMsgCreateTime];
    self.htTop = [aDecoder decodeDoubleForKey:kSearchMsgHtTop];
    self.htSource = [aDecoder decodeObjectForKey:kSearchMsgHtSource];
    self.createUser = [aDecoder decodeObjectForKey:kSearchMsgCreateUser];
    self.htName = [aDecoder decodeObjectForKey:kSearchMsgHtName];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_htId forKey:kSearchMsgHtId];
    [aCoder encodeObject:_createTime forKey:kSearchMsgCreateTime];
    [aCoder encodeDouble:_htTop forKey:kSearchMsgHtTop];
    [aCoder encodeObject:_htSource forKey:kSearchMsgHtSource];
    [aCoder encodeObject:_createUser forKey:kSearchMsgCreateUser];
    [aCoder encodeObject:_htName forKey:kSearchMsgHtName];
}

- (id)copyWithZone:(NSZone *)zone
{
    SearchMsg *copy = [[SearchMsg alloc] init];
    
    if (copy) {

        copy.htId = self.htId;
        copy.createTime = [self.createTime copyWithZone:zone];
        copy.htTop = self.htTop;
        copy.htSource = [self.htSource copyWithZone:zone];
        copy.createUser = [self.createUser copyWithZone:zone];
        copy.htName = [self.htName copyWithZone:zone];
    }
    
    return copy;
}


@end
